angular.module('app').config(($stateProvider) => {

    $stateProvider.state('app', {
        url        : '/app',
        abstract   : true,
        templateUrl: 'view/app/app.html'
    })
    ;
}).run(($state, $rootScope)=> {
    let menus, home;
    menus = $state.get().filter(item => item.name.indexOf('app.') !== -1);
    // home 菜单置顶
    home = menus.find(item=> item.name === 'app.home');
    if (home) {
        menus.splice(menus.indexOf(home), 1);
        menus.unshift(home);
    }
    $rootScope.menus = menus;

    $rootScope.$on('$stateChangeSuccess', function (e, to) {
        $rootScope.viewTitle = to.label;
    });
});